package com.preparation.dto;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class R {
    private int code;       // 状态码
    private Object data;    // 数据
    private String message; // 消息

    public R(int code, Object data) {
        this.code = code;
        this.data = data;
    }

    public R(int code, String message) {
        this.code = code;
        this.message = message;
    }

    // 成功响应 带数据
    public static R success(Object data, String message) {
        return new R(200, data, message);
    }

    public static R success(String message) {
        return new R(200, message);
    }

    // 失败响应
    public static R error(int code, String message) {
        return new R(code, message);
    }

    // 服务器错误
    public static R error(){
        return new R(500, "服务器错误，请稍后再试！");
    }

}
